//
//  Macros.h
//  XLXC
//
//  Created by HoldTime on 16/6/21.
//  Copyright © 2016年 holdtime. All rights reserved.
//

#ifndef Macros_h
#define Macros_h

//豪德天沐常用参数
#define BASEURL     [NSString stringWithFormat:@"%@/%@", SERVERIP, PROJECTNAME]
#define YC_BASEURL  [NSString stringWithFormat:@"%@/%@", YC_SERVERIP, YC_PROJECTNAME]

//#define SERVICE_UUID @"00003A06-0000-1000-8000-00805F9B34FB"
#define NOTIFY_UUID @"00002A05-0000-1000-8000-00805F9B34FB"
#define WRITE_UUID @"00002A09-0000-1000-8000-00805F9B34FB"

#define NOTIFY_UUID1 @"2A05"
#define WRITE_UUID1 @"2A09"
//常用
#define kWS(weakSelf)               __weak __typeof(&*self)weakSelf = self;
#define kUSER_DEFAULT              [NSUserDefaults standardUserDefaults]
#define kNOTIFICATION_DEFAULT      [NSNotificationCenter defaultCenter]
#define kIMGNAMED(NAME)            [UIImage imageNamed:NAME]
#define kIMGFROMBUNDLE(NAME)       [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@""]]
#define kCOLOR_RGB(r, g, b)        [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define kCOLOR_RGBA(r, g, b, a)    [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
#define kFONT_SIZE(X)              [UIFont systemFontOfSize:X]
#define kFONT_NAME_SIZE(N,S)       [UIFont fontWithName:N size:S]
#define kStringNotNil(_ref)        (_ref != nil) && (![_ref isEqualToString:@""])
#define kColorFromHex(rgbValue)    [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define SCREENWIDTH                [[UIScreen mainScreen] bounds].size.width//屏幕宽度
#define SCREENHEIGHT               [[UIScreen mainScreen] bounds].size.height//屏幕高度

// View 坐标(x,y)和宽高(width,height)
#define X(v)              (v).frame.origin.x
#define Y(v)              (v).frame.origin.y
#define WIDTH(v)          (v).frame.size.width
#define HEIGHT(v)         (v).frame.size.height

#define MinX(v)           CGRectGetMinX((v).frame)
#define MinY(v)           CGRectGetMinY((v).frame)

#define MidX(v)           CGRectGetMidX((v).frame)
#define MidY(v)           CGRectGetMidY((v).frame)

#define MaxX(v)           CGRectGetMaxX((v).frame)
#define MaxY(v)           CGRectGetMaxY((v).frame)

//设备类型
#define IS_IPHONE           (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPAD             (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

#define IS_IPHONE_5         (IS_IPHONE && SCREENHEIGHT == 568.0)
#define IS_IPHONE_6         (IS_IPHONE && SCREENHEIGHT == 667.0)
#define IS_IPHONE_6P        (IS_IPHONE && SCREENHEIGHT == 736.0)

//设备信息
#define IPAD_LANDSCAPE UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)
#define IPAD_PROTRAIT  UIInterfaceOrientationIsPortrait([UIApplication sharedApplication].statusBarOrientation)

#define IOS_VERSION          ([[[UIDevice currentDevice] systemVersion] floatValue])
#define SystemVersion        ([[UIDevice currentDevice] systemVersion])
#define kDEVICE_MODEL        ([[UIDevice currentDevice] model])

#define kAPP_NAME            [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]
#define kAPP_VERSION         [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
#define kAPP_SUB_VERSION     [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
#define kUDeviceIdentifier   [[UIDevice currentDevice] uniqueDeviceIdentifier]

//判断是否为空
#define kNotNilAndNull(_ref)  (((_ref) != nil) && (![(_ref) isEqual:[NSNull null]]))
#define kIsNilOrNull(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))

//检查系统版本
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

// PNG JPG 图片路径
#define PNGPATH(NAME)           [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"png"]
#define JPGPATH(NAME)           [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"jpg"]
#define PATH(NAME, EXT)         [[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]

// 加载图片
#define PNGIMAGE(NAME)          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"png"]]
#define JPGIMAGE(NAME)          [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"jpg"]]
#define IMAGE(NAME, EXT)        [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]]

// 字体大小(常规/粗体)
#define BOLDSYSTEMFONT(FONTSIZE)[UIFont boldSystemFontOfSize:FONTSIZE]

//屏幕
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))

#define MainScreenScale         [[UIScreen mainScreen] scale]// Screen Scale
#define Application_Frame       [[UIScreen mainScreen] applicationFrame]// App Frame
#define App_Frame_Height        [[UIScreen mainScreen] applicationFrame].size.height// App Frame Height
#define App_Frame_Width         [[UIScreen mainScreen] applicationFrame].size.width// App Frame Width

// 系统控件默认高度
#define kStatusBarHeight        (20.f)

#define kTopBarHeight           (44.f)
#define kBottomBarHeight        (49.f)

#define kCellDefaultHeight      (44.f)

#define kEnglishKeyboardHeight  (216.f)
#define kChineseKeyboardHeight  (252.f)

// 当前语言
#define CURRENTLANGUAGE         ([[NSLocale preferredLanguages] objectAtIndex:0])

// 本地化字符串
/** NSLocalizedString宏做的其实就是在当前bundle中查找资源文件名“Localizable.strings”(参数:键＋注释) */
#define LocalString(x, ...)     NSLocalizedString(x, nil)
/** NSLocalizedStringFromTable宏做的其实就是在当前bundle中查找资源文件名“xxx.strings”(参数:键＋文件名＋注释) */
#define AppLocalString(x, ...)  NSLocalizedStringFromTable(x, @"zjj", nil)

// App Name
#define AppDisplayName          [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]

/** 时间间隔 */
#define kHUDDuration            (1.f)

/** 一天的秒数 */
#define SecondsOfDay            (24.f * 60.f * 60.f)
/** 秒数 */
#define Seconds(Days)           (24.f * 60.f * 60.f * (Days))

/** 一天的毫秒数 */
#define MillisecondsOfDay       (24.f * 60.f * 60.f * 1000.f)
/** 毫秒数 */
#define Milliseconds(Days)      (24.f * 60.f * 60.f * 1000.f * (Days))

//由角度获取弧度 有弧度获取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)

#endif /* Macros_h */
